$(function() {
	admin.pubPromotion.init();
});
Namespace('admin.pubPromotion', {
	init : function() {
		easyui.util.initDatagrid('#datagrid', {
			onDblClickRow : function() {
			}
		});
	},
	query : function() {
		if (!$('#query-form').form('validate'))
			return;
		var data = $('#query-form').form('jsonObject');
		$('#datagrid').datagrid('load', data);
	},
	mallQuery : function() {
		if (!$('#query-form').form('validate'))
			return;
		var data = $('#query-form').form('jsonObject');
		$('#datagrid').datagrid('load', data);
	},
	mallPromotion:function(obj) {
		var sourceBizzId = $(obj).attr('sourceBizzId');
		var img = $(obj).attr('img');
		if (sourceBizzId != null) {
			top.addTab(sourceBizzId,'推广', contextPath+'/pub/promotion/toAdd?sourceBizzId=' + sourceBizzId+"&sourceBizzType="+1+"&img="+img);
		}
	},
	showPromotion:function(obj) {
		var sourceBizzId = $(obj).attr('sourceBizzId');
		var img = $(obj).attr('img');
		if (sourceBizzId != null) {
			top.addTab(sourceBizzId,'推广', contextPath+'/pub/promotion/toShow?sourceBizzId=' + sourceBizzId+"&sourceBizzType="+1+"&img="+img);
		}
	},
	add: function () {
	 	if(!$('#data-form').form('validate')) return;
        var data=$('#data-form').form('jsonObject');
        var url = contextPath + '/pub/promotion/create';
		$.post(url, data, function (result) {
			$('#datagrid').datagrid('loaded');
			if (result.code == 1) {
				top.showInfo('创建推广成功');
				top.addTab("",'商城产品推广', contextPath+'/pub/promotion/mallList');
			} else {
				top.showInfo(result.msg);
			}
		});

	},
	del: function (id) {
		var tip = "确定要取消吗";
		$.messager.confirm('信息提示', tip, function (success) {
			if (!success) {
				return;
			}
            var url = contextPath + '/pub/promotion/del';
			$('#datagrid').datagrid('loading');
			$.post(url, {'id': id}, function (result) {
				$('#datagrid').datagrid('loaded');
				if (result.code == 1) {
					top.showInfo('操作成功');
					top.addTab("",'商城产品推广', contextPath+'/pub/promotion/mallList');
				} else {
					top.showInfo(result.msg);
				}
			});

		});
	},
});